package com.bc.mes.api.controller.sms;

import com.bc.mes.service.SmsStaffService;
import com.bc.mes.common.api.CommonResult;
import com.bc.mes.common.dto.sms.SmsStaffLoginParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @version 1.0
 * @Author 小胤
 * @Date 2024/7/10 21:43
 * @注释
 */
@Controller
@Api(tags = "SmsStaffController", description = "用户管理")
@CrossOrigin(allowCredentials = "true")
public class SmsStaffController {
    @Autowired
    private SmsStaffService smsStaffService;
    @Value("${jwt.tokenHeader}")  //自动装载jwt
    private String tokenHeader;
    @Value("${jwt.tokenHead}")
    private String tokenHead;



    /**
     * 描述:登录
     */
    @ApiOperation(value = "登录（返回token）")
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult login(@RequestBody SmsStaffLoginParam smsStaffLoginParam) {
        String token = smsStaffService.login(smsStaffLoginParam.getUsername(), smsStaffLoginParam.getPassword());
        if (token == null) {
            return CommonResult.validateFailed("用户名或密码错误");
        }
        //如果 token不等于 null
        Map<String, String> tokenMap = new HashMap<>();
        tokenMap.put("token", token);
        tokenMap.put("tokenHead", tokenHead);
        return CommonResult.success(tokenMap);
    }
}
